package com.duobaoyu.dby.supply.admin.controller.invoice;

import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.common.core.validator.groups.Add;
import com.duobaoyu.dby.common.core.validator.groups.Edit;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.admin.converter.SupplyChainAdminConverter;
import com.duobaoyu.dby.supply.biz.service.invoice.InvoiceSettingService;
import com.duobaoyu.dby.supply.common.biz.dto.invoice.InvoiceSettingDTO;
import com.duobaoyu.dby.supply.common.biz.dto.invoice.InvoiceSettingQueryDTO;
import com.duobaoyu.dby.supply.common.biz.vo.invoice.InvoiceSettingVO;
import com.duobaoyu.dby.supply.db.entity.invoice.InvoiceSetting;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 发票设置
 *
 * @author jz
 * @version 1.0
 * @date 2022/6/5 09:27
 */
@RestController
@RequiredArgsConstructor
@Api(value = "发票设置", tags = "发票设置接口")
@RequestMapping("/admin/invoice-setting")
public class InvoiceSettingController {

	private final InvoiceSettingService invoiceSettingService;
	private final SupplyChainAdminConverter supplyChainAdminConverter;

	/**
	 * 发票设置列表
	 * @param invoiceSettingQuery
	 * @return
	 */
	@GetMapping("/page")
	@ApiOperation(value = "发票设置列表", notes = "发票设置列表")
	@SupplySysLog(value = "发票设置列表",operationType = OperationTypeEnum.SELECT)
	public R<List<InvoiceSettingVO>> queryPage(InvoiceSettingQueryDTO invoiceSettingQuery) {
		List<InvoiceSetting> invoiceSettings = invoiceSettingService.selectList(invoiceSettingQuery);
		return R.ok(supplyChainAdminConverter.toInvoiceSettingList(invoiceSettings));
	}

	/**
	 * 添加发票设置
	 * @param invoiceSettingAdd
	 * @return
	 */
	@PostMapping("/add")
	@ApiOperation(value = "添加发票设置", notes = "添加发票设置")
	@SupplySysLog(value = "添加发票设置",operationType = OperationTypeEnum.INTERT)
	public R<Boolean> add(@Validated(Add.class) @RequestBody InvoiceSettingDTO invoiceSetting) {

		return R.ok(invoiceSettingService.addSetting(invoiceSetting));
	}

	/**
	 * 修改发票设置
	 * @param invoiceSettingUpdate
	 * @return
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改发票设置", notes = "修改发票设置")
	@SupplySysLog(value = "修改发票设置",operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> update(@Validated(Edit.class) @RequestBody InvoiceSettingDTO invoiceSetting) {

		return R.ok(invoiceSettingService.updateSetting(invoiceSetting));
	}

	/**
	 * 删除发票设置
	 * @param id
	 * @return
	 */
	@DeleteMapping("/delete/{id}")
	@ApiOperation(value = "删除发票设置", notes = "删除发票设置")
	@SupplySysLog(value = "删除发票设置",operationType = OperationTypeEnum.DELETE)
	public R<Boolean> delete(@PathVariable("id") Long id) {
		return R.ok(invoiceSettingService.deleteById(id));
	}

}
